package com.lyun.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lyun.pojo.Movements;
import com.lyun.vo.MovementsVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface MovementsMapper extends BaseMapper<Movements> {

    List<Movements> selectByIds(List<Long> ids);

    @Select("select m.id , m.user_id, m.text_content, m.image_content, m.create_time,\n" +
            "               u.gender, u.nickname , u.header, u.age , u.tags\n" +
            "        from  tbl_movement m left join tbl_user u on m.user_id = u.id\n" +
            "        where m.id = #{id}")
    @Results({
            @Result(property = "createDate", column = "create_time"),
            @Result(property = "avatar", column = "header")
    })
    MovementsVo selectUserAndMovementById(Long movementId);

    @Select("select m.id , m.user_id, m.text_content, m.image_content, m.create_time,\n" +
            "               u.gender, u.nickname , u.header, u.age , u.tags\n" +
            "        from  tbl_movement m left join tbl_user u on m.user_id = u.id\n" +
            "        ORDER BY RAND() LIMIT #{randInt}")
    @Results({
            @Result(property = "createDate", column = "create_time"),
            @Result(property = "avatar", column = "header")
    })
    List<MovementsVo> getRecommendFriendListByRand(int randInt);

    List<MovementsVo> selectRecommendFriendListByIds(List<Long> ids);

    @Select("select m.id , m.user_id, m.text_content, m.image_content, m.create_time,u.gender, u.nickname , u.header, u.age , u.tags " +
            "from  tbl_movement m left join tbl_user u on m.user_id = u.id " +
            "where u.id = #{userId}")
    @Results({
            @Result(property = "createDate", column = "create_time"),
            @Result(property = "avatar", column = "header")
    })
    List<MovementsVo> selectMovementWithUser(Long userId);
}
